String.prototype.Trim=function(){   
	return   this.replace(/(^\s*)|(\s*$)/g,   "");   
} ; 
function checkTopSearchForm(){
	var keyword=document.getElementById("topKeywords").value.Trim();
	if(keyword==""){
		alert("关键字不能为空！");
		return false;
	}else{
		var text=keyword.replace(/([\u0391-\uFFE5])/ig,'mm');
		if(text.length < 2){
			alert("关键字太短了！");
			return false;
		}else if(text.length > 50){
			alert("关键字太长了！");
			return false;
		}else{
		   if(keyword.indexOf("&")>0){
			  keywordArray=keyword.split("&");
			  keyword=keywordArray[0];
		   }
		   keyword = keyword.replace(',','，');
		   keyword+=",title,keyword,b_author,b_isbn,code,b_contentsynopsis";
		}
	}
    //if(keyword!=""){
    //  keyword+=",title,keyword,b_author,b_isbn,code,b_contentsynopsis";
    //}//else{
      //搜索关键字不为空时 按销量倒数搜索
    	//document.getElementById("OrderBy").value="sellable.count0-int";
    	//document.getElementById("IsAsc").value="true";
    //}
    var thKeywords=document.getElementById("thKeywords");
    thKeywords.value=keyword;
    return true;
  }
var _srh_keyflag=true;
function submitSearchForm(){
 if(!checkTopSearchForm())return false;
 document.getElementById("searchform").submit();
} 

function judgeShowSuggest(){
	if(_srh_keyflag!=true){
		return;
	}
	_srh_keyflag=false;
	
	try{
	jQuery.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8";
	}catch(e){}
	jQuery("#topKeywords").suggest("${frontPath}/AutoComplete",{
			minchars:1,
            onSelect: function() { 	
					var comText=this.value+'';
					jQuery("#topKeywords").val(comText);
					try{jQuery("#idx_useAutoComplete").val(1);submitSearchForm();}catch(e){alert(e.name+':'+e.message);}
					_srh_keyflag=true;
            	}
           }            
        );     
}